package com.lyz.anli;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 2022/2/12 (买一张可以，需要上锁，不然会污染数据，需完善)
 */
public class De7ssqiu {
    public static void main(String[] args) {
    //用户奖票

        //买票张数
        Scanner scanner = new Scanner(System.in);
        System.out.print("买票张数：");
        int cjcs = scanner.nextInt();
        System.out.println();

        //录票
        int[][] jphong = new int[cjcs][6];
        int[][] jplan = new int[cjcs][1];
        for (int i = 0; i <= 1 ; i++) {
            choujiang(jphong,jplan);
        }

        //双色球开奖
        int[] hong = new int[6];
        int[] lan = new int[1];
        choujiang(hong,lan);
        System.out.print("开奖："+Arrays.toString(hong)+""+Arrays.toString(lan));
        System.out.println();

        //兑奖
        for (int i = 0; i < cjcs; i++) {
            System.out.print("票"+(i+1)+ewdayi(jphong,i)+ewdayi(jplan,i));
            System.out.println(kaijiang(jphong,jplan,hong,lan,i));
        }
    }
    /**
     * 生成任意球号
     * @param qiu
     * @param n
     */
    public static void yaohao(int[] qiu,int n){
        for (int i = 0; i < qiu.length; i++) {
            qiu[i]=(int)(Math.random()*n+1);
        }
    }
    public static void yaohao(int[][] qiu,int n){
        for (int i = 0; i < qiu.length; i++) {
            for(int j=0;j<qiu[i].length;j++){
                qiu[i][j]=(int)(Math.random()*n+1);
            }
        }
    }

    /**
     * 生成奖票
     * @param hong
     * @param lan
     */
    public static void choujiang(int[] hong,int[] lan){
        final int honghao = 33;
        final int lanhao = 16;
        yaohao(hong,honghao);
        yaohao(lan,lanhao);
    }
    public static void choujiang(int[][] hong,int[][] lan){
        final int honghao = 33;
        final int lanhao = 16;
        yaohao(hong,honghao);
        yaohao(lan,lanhao);
    }

    /**
     * 开奖方法
     * @param yho
     * @param yla
     * @param hong
     * @param lan
     * @param n
     * @return
     */
    public static String kaijiang(int[][] yho,int[][] yla,int[] hong,int[] lan,int n){
        int a = duipiao (yho, hong, n);
        int b = duipiao (yla, lan, n);
        return duipiao(a,b);
    }
    public static int duipiao(int[][] yh,int[] xt,int n){
        int ci = 0;
        for (int i = 0; i < yh.length; i++) {
            for (int j = 0; j < yh[n].length; j++) {
                if(yh[n][j]==xt[j]){
                    ci+=1;
                }
            }
        }
        return ci;
    }
    public static String duipiao(int a,int b){
        if(a==6&&b==1){
            return "一等奖 1000万";
        }
        if(a==6){
            return "二等奖 500万";
        }
        if(a==5&&b==1){
            return "三等奖 3000";
        }
        if(a==5||a==4&&b==1){
            return "四等奖 200";
        }
        if(a==4||a<=3&&a>=2&&b==1){
            return "五等奖 10";
        }
        if(a==1||b==1){
            return "六等奖 5";
        }
        return "未中奖";
    }
    /**
     * 遍历二维数组
     * @param a
     * @param wei
     * @return
     */
    public static String ewdayi (int[][] a,int wei){
        if (a == null){
            return "null";
        }
        int iMax = a[0].length - 1;
        if (iMax == -1){
            return "[]";
        }

        StringBuilder b = new StringBuilder();
        b.append('[');
        for (int i = 0; ; i++) {
            b.append(a[wei][i]);
            if (i == iMax){
                return b.append(']').toString();
            }
            b.append(", ");
        }
    }
}
